/** @file ButtonIcon.qml
@brief Iconic button with custom image and optional text

ButtonIcon is a button that can show text but it should be used to
create an iconized button.
To be able to open the object with the framework loader and also with
the subloader - when ButtonIcon is part of a compound object - some values
are not get from the loader with the usual method call i.e. \e objLoad.get_methodName()
but using a function from inside the object itself.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0
import "Theme.js" as JsObj

BorderImage {
    id: button

    signal objClicked

    source: objLoad.getIcon(); clip: true
    border { left: 10; top: 10; right: 10; bottom: 10 }

    width: objLoad.getWidth()
    height: objLoad.getHeight()

    function setProperties(wi, he, icon, text) {
        width = wi;
        height = he;
        source = icon;
        buttonText.text = text;
    }

    // Shade is set over the button image when it is presed
    Rectangle { id: shade; anchors.fill: button; radius: 5; color: "black"; opacity: 0 }

    Text {
        id: buttonText

        anchors.centerIn: parent;
        font.pointSize: objLoad.getFontPoints();
        text: objLoad.getString();
        style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: { button.objClicked(); }
    }

    // When button is pressed the shade changes
    states: State {
        name: "pressed"; when: mouseArea.pressed == true
        PropertyChanges { target: shade; opacity: .2 }
    }
}
